const JwtStrategy = require('passport-jwt').Strategy //解密验证
const ExtractJwt = require('passport-jwt').ExtractJwt;
const keys = require('./keys')

var opts = {}
opts.jwtFromRequest = ExtractJwt.fromAuthHeaderAsBearerToken()
opts.secretOrKey = keys.secretOrkey

const User = require('../routes/moduls/User') //数据库存储模板

module.exports = passport => {
    passport.use(
        new JwtStrategy(opts,async (jwt_payload, done) => {
            const user = await User.find({_id:jwt_payload.id});
            if (user) {
                return done(null, user);
            }
            else {
                return done(null, false);
            }
        })
    )
}